<?php
session_start(); 
require_once('KLogger.php');   
$log = new KLogger ( "./logs/loginTracker.txt" , KLogger::DEBUG );
?>

<?php
$username = $_SESSION['username'];
if($username==null || $username== ""|| $username == "")
{
	header('Location: http://172.26.195.159/checklist/php/logout.php');
}
?>

<html>
<head>
<title>Validating login</title>
</head>
<body>



<?php

$username=$_POST['username'];
$password=$_POST['password'];


$con = mysql_connect("localhost","root","");
 /*if (!$con)
  {
   die("Could not connect: " . mysql_error());
   }
*/

 // Create table
 mysql_select_db("checklist", $con);
 
$result = mysql_query("select * from employees where username = '".$_POST['username']."'"." and password = '".$_POST['password']."'");
   //where name = ".$_POST['username'].""

if($row = mysql_fetch_array($result))
   {
   $_SESSION['username'] =  $username;
   $_SESSION['password']  = $password;
   $_SESSION['fullname'] =  $row['fullname'];
   $_SESSION['role']     =  $row['role'];
   
   $log->logInfo('processLogin[49] Successful Login  :'.$username);
   //Redirect to welcome page
   header('Location: http://172.26.195.159/checklist/php/welcome.php');
   }
   else
   {
   $_SESSION['authentication_error'] = "Sorry , Authentication Failure";
   header('Location: http://172.26.195.159/checklist/php/index.php');
   }

 mysql_close($con);
	
?>

<!-- $row = mysql_fetch_array($result)  -->

</body>
</html>